#pragma strict
//////////////////////////////////////////////////////
///反方向旋转时,从359.9开始.360会出错.
//////////////////////////////////////////////////////
var anglePerSec:float = 90;
var maxAngle:float = 90;

var time:float = 1;

var speed:float;

var isRot:boolean;

function Start () {
	maxAngle = WrapAngle(maxAngle);
	
	if(time != 0)
		speed = anglePerSec / time;
}

function Update () {
	if(IsNeedRotate()){
		transform.Rotate(Vector3.up * speed * Time.deltaTime);
	}
}

private function IsNeedRotate():boolean{
	var isNeed:boolean = false;
	if(anglePerSec > 0)
		isNeed = transform.localEulerAngles.y < maxAngle;
	else 
		isNeed = transform.localEulerAngles.y > maxAngle;
	return isNeed && isRot;
}

private function WrapAngle(anglePerSec:float):float{
	if(anglePerSec < 0)
		return anglePerSec + 360;
	else if(anglePerSec > 360)
		return anglePerSec - 360;
	return anglePerSec;
}